package com.ctshk.common.utils;

import com.ctshk.common.enums.MemberLevel;

/**
 * <p>
 *  会员等级计算工具类
 * </p>
 *
 * @author 李新科
 * @date 2021/6/17 13:33
 */
public class CalcMemberLevelUtil {

    /**
     *  根据定级积分和定级次数计算会员等级
     * @param ratingPoint 定级积分
     * @param ratingConsumptionTimes 定级消费次数
     * @return
     */
    public static int calcRatingLevel(int ratingPoint,int ratingConsumptionTimes) {
        if(ratingPoint >= MemberLevel.FIVESTARS.getRatingPoint() && ratingConsumptionTimes >= MemberLevel.FIVESTARS.getRatingConsumptionTimes()) {
            return MemberLevel.FIVESTARS.getLevel();
        } else if(ratingPoint >= MemberLevel.PLATINUM.getRatingPoint() && ratingConsumptionTimes >= MemberLevel.PLATINUM.getRatingConsumptionTimes()) {
            return MemberLevel.PLATINUM.getLevel();
        } else if(ratingPoint >= MemberLevel.GOLD.getRatingPoint() && ratingConsumptionTimes >= MemberLevel.GOLD.getRatingConsumptionTimes()) {
            return MemberLevel.GOLD.getLevel();
        } else {
            return MemberLevel.SILVER.getLevel();
        }
    }

    /**
     *  根据保级积分和保级次数计算会员等级
     * @param keepPoint 保级积分
     * @param keepConsumptionTimes 保级消费次数
     * @return
     */
    public static int calcKeepLevel(int keepPoint,int keepConsumptionTimes) {
        if(keepPoint >= MemberLevel.FIVESTARS.getKeepPoint() && keepConsumptionTimes >= MemberLevel.FIVESTARS.getKeepConsumptionTimes()) {
            return MemberLevel.FIVESTARS.getLevel();
        } else if(keepPoint >= MemberLevel.PLATINUM.getKeepPoint() && keepConsumptionTimes >= MemberLevel.PLATINUM.getKeepConsumptionTimes()) {
            return MemberLevel.PLATINUM.getLevel();
        } else if(keepPoint >= MemberLevel.GOLD.getKeepPoint() && keepConsumptionTimes >= MemberLevel.GOLD.getKeepConsumptionTimes()) {
            return MemberLevel.GOLD.getLevel();
        } else {
            return MemberLevel.SILVER.getLevel();
        }
    }
}
